package com.atguigu.config;

import com.atguigu.bean.Color;
import com.atguigu.bean.ColorFactoryBean;
import com.atguigu.bean.Person;
import com.atguigu.bean.Red;
import com.atguigu.condition.ConditionLinux;
import com.atguigu.condition.ConditionWindows;
import com.atguigu.condition.MyImportBeanDefinitionRegis;
import com.atguigu.condition.MyImportSelector;
import org.springframework.context.annotation.*;

//通过注解的方法不用添加bean
@Configuration
@Import({Color.class, Red.class, MyImportSelector.class, MyImportBeanDefinitionRegis.class}) //导入组件，组件的id就是全类名
public class MainConfig2 {
    @Lazy
    @Bean
    public Person person() {
        System.out.println("给容器中添加Person...");
        return new Person("张三", 25);
    }

    /**
     * @Condiotional 按照一定的条件加入容器
     *
     */
    @Bean("Bill")
    @Conditional({ConditionWindows.class})
    public Person person01() {
        return new Person("Bill Gates", 62);
    }

    @Bean("linux")
    @Conditional({ConditionLinux.class})
    public Person person02() {
        return new Person("Linux", 48);
    }

    @Bean
    public ColorFactoryBean colorFactoryBean() {
        return new ColorFactoryBean();
    }
}
